<html lang="zh-CN"><head><meta charset="UTF-8"><style>.nodata  main {width:1000px;margin: auto;}</style></head><body class="nodata " style=""><div class="main_father clearfix d-flex justify-content-center " style="height:100%;"> <div class="container clearfix " id="mainBox"><main><div class="blog-content-box">
<div class="article-header-box">
<div class="article-header">
<div class="article-title-box">
<h1 class="title-article" id="articleContentId">(C卷,100分)- 工号不够用了怎么办？（Java & JS & Python & C）</h1>
</div>
</div>
</div>
<div id="blogHuaweiyunAdvert"></div>

        <div id="article_content" class="article_content clearfix">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-044f2cf1dc.css">
                <div id="content_views" class="htmledit_views">
                    <p id="main-toc"><strong>目录</strong></p> 
<p id="%E9%A2%98%E7%9B%AE%E6%8F%8F%E8%BF%B0-toc" style="margin-left:80px;"><a href="#%E9%A2%98%E7%9B%AE%E6%8F%8F%E8%BF%B0" rel="nofollow">题目描述</a></p> 
<p id="%E8%BE%93%E5%85%A5%E6%8F%8F%E8%BF%B0-toc" style="margin-left:80px;"><a href="#%E8%BE%93%E5%85%A5%E6%8F%8F%E8%BF%B0" rel="nofollow">输入描述</a></p> 
<p id="%E8%BE%93%E5%87%BA%E6%8F%8F%E8%BF%B0-toc" style="margin-left:80px;"><a href="#%E8%BE%93%E5%87%BA%E6%8F%8F%E8%BF%B0" rel="nofollow">输出描述</a></p> 
<p id="%E7%94%A8%E4%BE%8B-toc" style="margin-left:80px;"><a href="#%E7%94%A8%E4%BE%8B" rel="nofollow">用例</a></p> 
<p id="%E9%A2%98%E7%9B%AE%E8%A7%A3%E6%9E%90-toc" style="margin-left:80px;"><a href="#%E9%A2%98%E7%9B%AE%E8%A7%A3%E6%9E%90" rel="nofollow">题目解析</a></p> 
<p id="%E7%AE%97%E6%B3%95%E6%BA%90%E7%A0%81-toc" style="margin-left:80px;"><a href="#%E7%AE%97%E6%B3%95%E6%BA%90%E7%A0%81" rel="nofollow">算法源码</a></p> 
<hr id="hr-toc" /> 
<p></p> 
<h4 id="%E9%A2%98%E7%9B%AE%E6%8F%8F%E8%BF%B0">题目描述</h4> 
<ul><li>3020年&#xff0c;空间通信集团的员工人数突破20亿人&#xff0c;即将遇到现有工号不够用的窘境。</li><li>现在&#xff0c;请你负责调研新工号系统。继承历史传统&#xff0c;新的工号系统由小写英文字母&#xff08;a-z&#xff09;和数字&#xff08;0-9&#xff09;两部分构成。</li><li>新工号由一段英文字母开头&#xff0c;之后跟随一段数字&#xff0c;比如”aaahw0001″,”a12345″,”abcd1″,”a00″。</li><li>注意新工号不能全为字母或者数字,允许数字部分有前导0或者全为0。</li><li>但是过长的工号会增加同事们的记忆成本&#xff0c;现在给出新工号至少需要分配的人数X和新工号中字母的长度Y&#xff0c;求新工号中数字的最短长度Z。</li></ul> 
<p></p> 
<h4 id="%E8%BE%93%E5%85%A5%E6%8F%8F%E8%BF%B0">输入描述</h4> 
<ul><li>一行两个非负整数 X Y&#xff0c;用数字用单个空格分隔。</li><li>0&lt; X &lt;&#61;2^50 – 1</li><li>0&lt; Y &lt;&#61;5</li></ul> 
<p></p> 
<h4 id="%E8%BE%93%E5%87%BA%E6%8F%8F%E8%BF%B0">输出描述</h4> 
<ul><li>输出新工号中数字的最短长度Z</li></ul> 
<p></p> 
<h4 id="%E7%94%A8%E4%BE%8B">用例</h4> 
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;"><tbody><tr><td style="width:86px;">输入</td><td style="width:412px;">260 1</td></tr><tr><td style="width:86px;">输出</td><td style="width:412px;">1</td></tr><tr><td style="width:86px;">说明</td><td style="width:412px;">无</td></tr></tbody></table> 
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;"><tbody><tr><td style="width:86px;">输入</td><td style="width:412px;">26 1</td></tr><tr><td style="width:86px;">输出</td><td style="width:412px;">1</td></tr><tr><td style="width:86px;">说明</td><td style="width:412px;">数字长度不能为0</td></tr></tbody></table> 
<table border="1" cellpadding="1" cellspacing="1" style="width:500px;"><tbody><tr><td style="width:86px;">输入</td><td style="width:412px;">2600 1</td></tr><tr><td style="width:86px;">输出</td><td style="width:412px;">2</td></tr><tr><td style="width:86px;">说明</td><td style="width:412px;">无</td></tr></tbody></table> 
<p></p> 
<h4 id="%E9%A2%98%E7%9B%AE%E8%A7%A3%E6%9E%90">题目解析</h4> 
<p>这题应该就是一道数学问题。</p> 
<p>小写字母有26种&#xff0c;数字有10种&#xff0c;因此如果工号组合选择一个字母&#xff0c;一个数字的话&#xff0c;则有26 * 10 &#61; 260种。</p> 
<p>如果选择两个字母&#xff0c;两个数字的话&#xff0c;则会产生 26^2 * 10^2 种工号。</p> 
<p>现在确定了需要的工号总个数x&#xff0c;以及字母个数y&#xff0c;也就是说</p> 
<p>x &#61; 26^y * 10^z</p> 
<p>求最小的z&#xff0c;且z&gt;&#61;1。</p> 
<p>因此z的求解公式&#xff1a;</p> 
<p>z &#61; log(x / 26^y)</p> 
<p>这里我们要保证z向上取整&#xff0c;且保证z最小取1 </p> 
<p></p> 
<h4 id="%E7%AE%97%E6%B3%95%E6%BA%90%E7%A0%81">JavaScript算法源码</h4> 
<pre><code class="language-javascript">/* JavaScript Node ACM模式 控制台输入获取 */
const readline &#61; require(&#34;readline&#34;);

const rl &#61; readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

rl.on(&#34;line&#34;, (line) &#61;&gt; {
  const [x, y] &#61; line.split(&#34; &#34;).map(Number);

  console.log(Math.max(1, Math.ceil(Math.log10(x / Math.pow(26, y)))));
});
</code></pre> 
<p></p> 
<h4>Java算法源码</h4> 
<pre><code class="language-java">import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc &#61; new Scanner(System.in);

    long x &#61; sc.nextLong();
    int y &#61; sc.nextInt();

    System.out.println((long) Math.max(1, Math.ceil(Math.log10(x / Math.pow(26, y)))));
  }
}
</code></pre> 
<p></p> 
<h4>Python算法源码</h4> 
<pre><code class="language-python"># 输入获取
import math

x, y &#61; map(int, input().split())


# 算法入口
def getResult(x, y):
    print(max(1, math.ceil(math.log10(x / math.pow(26, y)))))


# 算法调用
getResult(x, y)
</code></pre> 
<p></p> 
<h4>C算法源码</h4> 
<pre><code class="language-cpp">#include &lt;stdio.h&gt;
#include &lt;math.h&gt;

int main() {
    double x;
    int y;

    scanf(&#34;%lf %d&#34;, &amp;x, &amp;y);

    printf(&#34;%d\n&#34;, (int) fmax(1.0, ceil(log10(x / pow(26, y)))));

    return 0;
}</code></pre>
                </div>
        </div>
        <div id="treeSkill"></div>
        <div id="blogExtensionBox" style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box"></div>
    <script>
  $(function() {
    setTimeout(function () {
      var mathcodeList = document.querySelectorAll('.htmledit_views img.mathcode');
      if (mathcodeList.length > 0) {
        for (let i = 0; i < mathcodeList.length; i++) {
          if (mathcodeList[i].naturalWidth === 0 || mathcodeList[i].naturalHeight === 0) {
            var alt = mathcodeList[i].alt;
            alt = '\\(' + alt + '\\)';
            var curSpan = $('<span class="img-codecogs"></span>');
            curSpan.text(alt);
            $(mathcodeList[i]).before(curSpan);
            $(mathcodeList[i]).remove();
          }
        }
        MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
      }
    }, 1000)
  });
</script>
</div></html>